# -*- coding: utf-8 -*-
'''
Created on Jan 10, 2021

@author: yl
'''

from FFT_Interpolation import *
from WangJiaNing_FFT import x, tau0, N, window_blackman

phi_set = np.linspace(0, 4*np.pi, num=100)
print(len(phi_set))
result_set = []
f = 5e6

for phi in phi_set:
    sig = np.cos(2*np.pi*f*x + phi)
    sig = sig * window_blackman
    # plt.plot(sig)
    # plt.show()
    freqline, sig_FFT, sig_freq, sig_phase = FFT_cal(sig, tau0)
    # phase_result = sig_phase[sig_freq.argmax()]
    phase_result = sig_phase[5]
    result_set.append(phase_result)
result_set = np.unwrap(result_set)
diff = result_set - phi_set
diff_nm = diff/2/np.pi*633/4

print(len(diff_nm))

plt.plot(phi_set,diff_nm,'b.-')

# plt.subplot(2,1,1)
# plt.plot(phi_set,'b')
# plt.plot(result_set,'r')
# plt.ylabel("Phase")
# plt.grid(which='major', axis='both')
# 
# plt.subplot(2,1,2)
# plt.plot(diff,'b', marker='o')
# plt.ylabel("Phase")
# plt.grid(which='major', axis='both')
# plt.tight_layout()
plt.show()